<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>MiniApp Demo</title>
    <script src="bridge.js"></script>
    <style>body{font-family:Arial,Helvetica,sans-serif;padding:20px}</style>
</head>
<body>
<h1>MiniApp Demo</h1>
<button id="btnEcho">Call native.echo</button>
<button id="btnTime">Call native.getTime</button>
<pre id="out"></pre>


<script>
    const out = document.getElementById('out')


    // 监听 Native 的回调
    window.addEventListener('message', (ev) => {
    try {
    const msg = ev.data
    out.textContent += '\n<< ' + JSON.stringify(msg)
    } catch (e) { }
    })


    document.getElementById('btnEcho').addEventListener('click', async () => {
    const res = await MiniApp.call('native.echo', { message: 'hello from miniapp' })
    out.textContent += '\n>> ' + JSON.stringify(res)
    })


    document.getElementById('btnTime').addEventListener('click', async () => {
    const res = await MiniApp.call('native.getTime')
    out.textContent += '\n>> ' + JSON.stringify(res)
    })
</script>
</body>
</html>